<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
	
	<table cellspacing="2" border="0" width="995">
		<tr>
			<td width="995" class="title_manager_product">Sửa video</td>
		</tr>
		<tr>
			<td>
				<table border="0" cellpadding="0" cellspacing="0" width="995">
					<tr>
						<td align="center">
							<table border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td align="center"><a href="index.php?admin=videoAdmin&do=formaddfile"><img src="images/CreateNews.gif" width="48" height="47" border="0" /></a></td>
								</tr>
								<tr>
									<td align="center" class="title_new_add"><a href="index.php?admin=videoAdmin&do=formaddfile">Tạo video</a></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>	
		</tr>
	</table>
	<?php
	$id=$_GET['id'];
	?>
<form action="index.php?admin=advAdmin&do=formeditfile&id=<?php echo $id;?>" method="post" enctype="multipart/form-data">
	<table class="reference" cellspacing="0" border="1" width="995">
		<tr>
			<td colspan="2" align="center">
				<?php
					$id=$_GET['id'];
					$videoname=$_POST['videoname'];
					$videopath = $_POST['videopath'];
					
					$state = $_POST['state'];
					
					$target="../user/upload/adv/";
					$image = $_FILES['imgpath']['name'];
					$link=$target.$image;
					$errors = array();
					if(isset($_POST['submit'])){
						move_uploaded_file($_FILES['imgpath']['tmp_name'],$link);
						if($image==''){
							$query="UPDATE advertisements SET nameAdv='$nameAdv',linkAdv='$linkAdv',position='$position',state='$state' WHERE id=$id";		
						}else{
							$query="UPDATE advertisements SET nameAdv='$nameAdv',linkAdv='$linkAdv',imgpath='$link',position='$position',state='$state' WHERE id=$id";		
						}
						
						if($nameAdv==''){
								$errors[] = "<font color=\"red\">Bạn chưa nhập tên quảng cáo.</font>";
						}
						if($linkAdv==''){
							$errors[] = "<font color=\"red\">Bạn chưa nhập liên kết quảng cáo.</font>";
						}
						if (sizeof($errors) > 0) {
							echo "<ul>";
								foreach ($errors as $e) {
								echo "<li>$e</li>";
							}
							echo "</ul>";
						}else{
							mysql_query($query);
							echo "Sửa quảng cáo thành công.";
							echo "<script>window.location='index.php?admin=advAdmin&do=listadv'</script>";
						}		
					}
				?>
			</td>
		</tr>
		<?php
            
            $query="SELECT * FROM advertisements WHERE id=$id";
            $result=mysql_query($query);
            while($row=mysql_fetch_array($result)){?>
                <tr><td height="20"></td></tr>
                <tr>
                    <td align="right" width="205"><b>Tên quảng cáo:</b></td>
                    <td width="700"><input type="text" name="nameAdv" size="40" value="<?php echo $row['nameAdv']?>" /></td>
                </tr>
				<tr>
                    <td align="right"><b>Liên kết quảng cáo:</b></td>
                    <td><input type="text" name="linkAdv" size="40" value="<?php echo $row['linkAdv']?>" /></td>
                </tr>
				<tr>
					<td align="right"><b>Đường dẫn ảnh</b></td>
					<td><input type="file" name="imgpath"></td>
            	</tr>
                <tr>
                    <td align="right"><b>Vị trí:</b></td>
                    <td>
						<!--
						<select name="position">
							<option value="left" <?php 
								if($row['position']=='left'){
									echo "selected";
								}
							?>>Bên trái</option>
							<option value="right" <?php
								if($row['position']=='right'){
									echo "selected";
								}
							?>>Bên phải</option>
							<option value="top" <?php
								if($row['position']=='top'){
									echo "selected";
								}
							?>>Bên trên</option>
						</select>
						-->
						
						<select name="position">
							
							<option value="right" <?php
								if($row['position']=='right'){
									echo "selected";
								}
							?>>Bên phải</option>
							
						</select>
					</td>
                </tr>
				<tr>
					<td align="right"><b>Trạng thái:</b></td>
					<td>
						<select name="state">
							<option value="on" <?php 
								if($row['state']=='on'){
									echo "selected";
								}
							?>>Hiện tin</option>
							<option value="off" <?php
								if($row['state']=='off'){
									echo "selected";
								}
							?>>Ẩn tin</option>
						</select>
					</td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="submit" value="Sửa quảng cáo" /></td>
                </tr>
            <?php
            }
            ?>	        	
        </table>
    </form>
</body>
</html>